package com.hfut.eeg.controller;

import cn.hutool.core.lang.Console;
import com.hfut.eeg.common.api.CommonResult;
import com.hfut.eeg.dto.ReportInfo;
import com.hfut.eeg.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * 智能生成报告
 */
@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    ReportService reportService;

    /**
     * 更新报告
     * @param reportInfo
     * @return
     */
    @RequestMapping(value="/updateReport",method = RequestMethod.POST)
    public CommonResult insertReport(@RequestBody ReportInfo reportInfo) {
        int i = reportService.updateReport(reportInfo);
        Console.log(reportInfo);
        if(i>=1)
            return CommonResult.success(reportInfo);
        else
            return CommonResult.failed();
    }

    /**
     * 获取指定病人报告
     * @param patientId
     * @return
     */
    @RequestMapping(value = "/getReport")
    public CommonResult getReport(String patientId) {
        System.out.println(patientId);
        ReportInfo reportInfo = null;
        try {
            reportInfo = reportService.getReport(patientId);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if(reportInfo==null){
            return CommonResult.failed();
        }else{
            return CommonResult.success(reportInfo);
        }
    }

}
